--[[
/**
 * 援护
 * [0]	时间间隔
 * [1] 无敌buffId
 * [2] 护盾buffId
 * [3] buff层数
 */
]]
---@class BuffEffect14100 : BaseBuffEffect
BuffEffect14100 = ClientFight.CreateClass("BuffEffect14100", ClientFight.BaseBuffEffect)
local t = BuffEffect14100
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters =  {...}
    local source = buff.source;
    local fightResult =  parameters[3];
    local tiggerSkill =  parameters[2];
    if (fightResult.state == DamageResultTypeEnum.HEAL) then
    return IBuffEffect.FAIL;
   end
    if (fightResult.damage <= 0) then
    return IBuffEffect.FAIL;
   end
    -- 分摊者已经死亡
    if (source:isDie()) then
    return IBuffEffect.REMOVE;
   end
    if (source.fighterId == buff.target.fighterId) then
    return IBuffEffect.REMOVE;
   end
    local fighterMaxHp = FighterAttributeManager.getFightAttr(source, FighterAttributeEnum.HP);
    local fighterHpPercent =  (source.hp * Global.TEN_THOUSANDTH / fighterMaxHp);

    -- 承担百分比
    local percent = buff.buffBean.f_BuffEffectValue[1];
    if (fighterHpPercent < buff.buffBean.f_BuffEffectValue[3]) then
    percent = buff.buffBean.f_BuffEffectValue[2];
   end

    -- 转移的伤害
    local moveDamage =  (percent * fightResult.damage / Global.TEN_THOUSANDTH);

    if (moveDamage <= 0) then
    return IBuffEffect.FAIL;
   end

    -- 伤害修正系数
    -- int hurtCorrectFactor = buff.buffBean.f_BuffEffectValue[3];
    fightResult.damage = fightResult.damage - moveDamage;
    local attacker = source;
    if parameters[1] then
    attacker =  parameters[1];
   end
    if (table.getn(buff.buffBean.f_BuffEffectValue)  > 5) then
    moveDamage = moveDamage * Utils.toRatio(buff.buffBean.f_BuffEffectValue[6]);
   end
    if (not table.contains(source.totalSign.signs,FighterSignEnum.TAG_1006))then
    local realDamage = DamageManager.setFighterHp(fight, source, attacker, nil, DamageResultTypeEnum.NORMAL,
    -moveDamage, source.hp - moveDamage, true, true, true);
   end
    -- 加一个连线的表现buff
    BuffManager.addBuff(fight, buff.skill, buff.source, buff.target, false, buff.buffBean.f_BuffEffectValue[4], buff.buffBean.f_BuffEffectValue[5]);
    local logmoveDamage = moveDamage;
    SkillRoleMgr.savePathFile(
    "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
    .. buff.modelId .. " 触发伤害承担  承担者:" .. source.fighterId .. "  被承担者:"
    .. buff.target.fighterId .. "承担伤害:" .. logmoveDamage);

    return ClientFight.BaseBuffEffect.action(self,fight, buff, ...);
end

t.New()